Package pydbg :: Module my_ctypes
[show private | hide private]
[frames | no frames]

Module pydbg.my_ctypes


Author: Pedram Amini

Contact: pedram.amini@gmail.com

Organization: www.openrce.org

License: GNU General Public License 2.0 or later

Function Summary
Mixed _construct(typ, raw_bytes)
This routine is called by _reduce for unmarshaling purposes.
Tuple _reduce(self)
cPickle will allow an object to marshal itself if the __reduce__ function is defined.

Variable Summary
tuple c_types = (<type '_ctypes.Structure'>, <class 'ctypes.c_...

Function Details

_construct(typ, raw_bytes)

This routine is called by _reduce for unmarshaling purposes. The object type is used to instantiate a new object of the desired type. The raw bytes are then directly written into the address space of the newly instantiated object via the ctypes routines memmove() and addressof().
Parameters:
typ - The class type of the object we are unmarshaling.
           (type=Class object)
raw_bytes - The raw bytes
           (type=Raw bytes (in a string buffer))
Returns:
Unmarshaled object.
           (type=Mixed)

_reduce(self)

cPickle will allow an object to marshal itself if the __reduce__ function is defined. Because cPickle is unable to handle ctype primitives or the objects derived on those primitives we define this function that later is assigned as the __reduce__ method for all types. This method relies on _construct for unmarshaling. As per the Python docs __reduce__ must return a tuple where the first element is "A callable object that will be called to create the initial version of the object. The next element of the tuple will provide arguments for this callable...". In this case we pass the object class and the raw data bytes of the object to _construct.
Returns:
Tuple, as specified per the cPickle __reduce__ Python docs.
           (type=Tuple)

Variable Details

c_types

Type:
tuple
Value:
(<type '_ctypes.Structure'>,
 <class 'ctypes.c_char'>,
 <class 'ctypes.c_byte'>,
 <class 'ctypes.c_ubyte'>,
 <class 'ctypes.c_short'>,
 <class 'ctypes.c_ushort'>,
 <class 'ctypes.c_long'>,
 <class 'ctypes.c_ulong'>,
...                                                                    

Generated by Epydoc 2.1 on Fri Jun 16 17:16:24 2006 http://epydoc.sf.net